#include "Maze.h"

Maze::Maze (int numPoints, int distance, int w, int h)
{
    index = 0;
	width = w;
	height = h;
	
    disk = new PoissonDisks(numPoints, distance, width, height);
	vector<Point*> points = disk->getPoints();
	
    //creates a Priority Queue to sort out the points
    pointsorter = new HeapPQueue<Point*, PointCompare>(4);
    unsigned int x = 0;
    //loop to insert the points into priority queue for sorting
    while ( x< points.size() )
    {
        pointsorter->insert(points[x]);
        x++;
    }
    //loop to insert the points returned from priority queue.
    //deleteMin returns the pointers with the minimum X. If X is the same between two pointers then smaller Y
    while(!pointsorter->isEmpty())
    {
        Point* temp;
        pointsorter->deleteMin(temp);
        pointlist.push_back(temp);
        index++;
    }
    //Now pointlist sorted

    //creates triangulator to triangulate using the points
    Triangulator* triangulate = new Triangulator(width, height, pointlist);
    //returns list of triangles from the triangulate
    trilist = triangulate->getTriangles();
    //Constructor PathCreator that takes all the triangles
    //Decides whether it should create a path between triangles
    PathCreator* givemeedges = new PathCreator (width, height, trilist);
    //PathCreator returns the list of edges
    edgelist = givemeedges->getEdges();
}

Maze::~Maze()
{
}

vector<Point*> Maze::getPoints()
{
    return pointlist;
}

vector<Edge*> Maze::getEdges()
{
    return edgelist;
}

vector<Triangle*> Maze::getTriangles()
{
    return trilist;
}

void Maze::printPoints()
{
    //initializes the index for pointlist
	int f = 0;
	//loop to print each point in the pointlist
        while (pointlist[f] != NULL)
        {
            pointlist[f]->print();
	    f++;
        }

}

void Maze::printPoisson(){
    disk->printPoints();
}
